<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="账号">
      <el-input v-model="form.userName" />
    </el-form-item>
    <el-form-item label="密码">
      <el-input type="password" v-model="form.passWord" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import md5 from 'js-md5'
export default {
  name: 'login',
  data(){
    return {
      form:{
        userName: '',
        passWord:''
      }
    }
  },
  methods:{
    async onSubmit(){
      console.log(this.$router)
      let res = await (await fetch(`http://localhost:3000/login`,{
        method:'POST',
        headers:{
          'Content-Type': 'application/json'
        },
        body:JSON.stringify({
          userName:this.form.userName,
          passWord:md5(this.form.passWord)
        })
      })).json()
      console.log(res)
      // this.$router.push({ path: '/index',query:{id:1,name:'张三'} })
    }
  },
  mounted(){
    let id = this.$route.params.id
    console.log(id)
  }
}
</script>
